package org.mj.im.server.netty.processor.impl;


import org.mj.im.common.MessageSenderService;
import org.mj.im.common.constants.IMConstants;
import org.mj.im.common.enums.IMSendCode;
import org.mj.im.common.model.IMReceiveInfo;
import org.mj.im.common.model.IMSendResult;
import org.mj.im.common.model.IMUserInfo;

public class BaseMessageProcessor {
    private final MessageSenderService senderService;

    public BaseMessageProcessor(MessageSenderService messageSenderService) {
        this.senderService = messageSenderService;
    }

    protected void sendPrivateMessage(IMReceiveInfo receiveInfo, IMSendCode sendCode){
        if (receiveInfo.isSendResult()){
            IMSendResult<?> result = new IMSendResult<>(receiveInfo.getSender(),
                    receiveInfo.getReceivers().get(0),
                    sendCode.getCode(),
                    receiveInfo.getData());
            String sendKey = IMConstants.IM_RESULT_PRIVATE_QUEUE;
            result.setDestination(sendKey);
            senderService.send(result);
        }
    }

    protected void sendGroupMessageResult(IMReceiveInfo receiveInfo, IMUserInfo imUserInfo, IMSendCode sendCode){
        if (receiveInfo.isSendResult()){
            IMSendResult<?> imSendResult = new IMSendResult<>(receiveInfo.getSender(),imUserInfo,sendCode.getCode(),receiveInfo.getData());
            imSendResult.setDestination(IMConstants.IM_RESULT_GROUP_QUEUE);
            senderService.send(imSendResult);
        }
    }






}